const {ccclass, property} = cc._decorator;

@ccclass
export default class UI_Ctr extends cc.Component {

    private view = {};

    //将所有的节点存到view 表里
    load_all_object(root:cc.Node, path: string) {
        for(let i = 0; i < root.childrenCount; i ++) {
            this.view[path + root.children[i].name] = root.children[i];
            this.load_all_object(root.children[i], path + root.children[i].name + "/");
        }
    }
    // LIFE-CYCLE CALLBACKS:
    onLoad () {
        this.view = {};
        this.load_all_object(this.node, "");
    }

    AddButtonListener(view_name:string, caller, func) {
        var view_node = this.view[view_name];
        if (!view_node) {
            cc.error("the node name of " + view_name + " not have cc.Button");
            return;
        }
        
        var button = view_node.getComponent(cc.Button);
        if (!button) {
            return;
        }

        view_node.on("click", func, caller);
    }

}
